package com.stormrage.edu.dao.index.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.index.IdxTrialDao;
import com.stormrage.entity.index.IdxTrial;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: IdxTrialDaoImpl.java
 * @Package com.stormrage.edu.dao.index.impl
 * @Description: 试看课件 Dao
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Repository
public class IdxTrialDaoImpl extends MysBaseDao implements IdxTrialDao {

	private static final Logger logger = LoggerFactory.getLogger(IdxTrialDaoImpl.class);

	@Override
	public Integer create(final IdxTrial arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Create 】- 开始运行 ");

		final String query = "INSERT INTO idx_trial (trial, url, image)" + " VALUES (:trial, :url, :image)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Create 】- 完成运行 ");
		return index;

	}

	@Override
	public void update(final IdxTrial arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Update 】- 开始运行 ");

		final String query = "UPDATE idx_trial SET trial = :trial WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Update 】- 完成运行 ");

	}

	@Override
	public void delete(Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Delete 】- 开始运行 ");

		final String query = "DELETE FROM idx_trial WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 Delete 】- 完成运行 ");

	}

	@Override
	public IdxTrial queryById(Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM idx_trial WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		IdxTrial entity = queryObject(query, IdxTrial.class, map);

		logger.debug(" 【 Dao 】-【 IdxQandaDao 】-【 QueryList 】- 完成运行 ");
		return entity;

	}

	@Override
	public List<IdxTrial> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 IdxImageDao 】-【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM idx_trial";
		logger.debug(" 数据库执行语句为 " + query);

		List<IdxTrial> array = queryList(query, IdxTrial.class);

		logger.debug(" 【 Dao 】-【 IdxImageDao 】-【 QueryList 】- 完成运行 ");
		return array;

	}

}
